package com.yinp.proapp.module.baidu_map.activity;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.yinp.proapp.base.App;
import com.yinp.proapp.base.activity.AppBaseActivity;
import com.yinp.proapp.databinding.ActivityBaiduMapSearchBinding;
import com.yinp.proapp.greendao.DaoUtils;
import com.yinp.proapp.module.baidu_map.adapter.BaiduMapSearchAdapter;
import com.yinp.proapp.module.baidu_map.bean.BaiduMapSearchBean;
import com.yinp.proapp.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yinp
 * @Date: 2021/10/11
 * @Description:百度地图的搜索
 */
public class BaiduMapSearchActivity extends AppBaseActivity<ActivityBaiduMapSearchBinding> {
    /**
     * 分页查询数据
     */
    private DaoUtils<BaiduMapSearchBean> baiduMapSearchBeanDaoUtils;
    private int page = 0;
    private List<BaiduMapSearchBean> mapSearchList;
    private BaiduMapSearchAdapter baiduMapSearchAdapter;

    @Override
    protected void initViews() {
        setStatusBarHeight(StatusBarUtil.getStatusBarHeight(mContext));

        baiduMapSearchBeanDaoUtils = new DaoUtils<>(BaiduMapSearchBean.class, App.daoSession.getBaiduMapSearchBeanDao());
        initRecycler();
        initHistoryData();
    }

    /**
     * 获取历史数据
     */
    private void initHistoryData() {
        mapSearchList = baiduMapSearchBeanDaoUtils.queryPageList(BaiduMapSearchBean.class, page);
        baiduMapSearchAdapter.notifyDataSetChanged();
    }

    private void initRecycler() {
        if (mapSearchList == null) {
            mapSearchList = new ArrayList<>();
        }
        baiduMapSearchAdapter = new BaiduMapSearchAdapter(mapSearchList);
        bd.rvRecordList.setHasFixedSize(true);
        bd.rvRecordList.setLayoutManager(new LinearLayoutManager(mContext));
        bd.rvRecordList.setAdapter(baiduMapSearchAdapter);
    }
}